# encoding: utf-8

from flask import Blueprint, render_template, request
from .models import Company

bp = Blueprint("front", __name__)


@bp.route('/')
def index():
    page = request.args.get('page', 1, type=int)
    scales = request.args.getlist('scale')
    args = {
        "scale": scales
    }
    if scales:
        pagination = Company.query.filter(Company.scale.in_(scales)).paginate(page, 10)
    else:
        pagination = Company.query.paginate(page, 10)
    data = pagination.items
    return render_template('front/index.html', data=data, pagination=pagination, args=args)
